#!/bin/sh 

apt-get install -y lsb 

UVERSION=$(lsb_release -sc)

if [ `whoami` != "root" ] ; then 
    echo "$0: You must be root to run this script, dude"
    exit 1
fi

echo "Running Icetray setup for Ubuntu '$UVERSION'"

COMMON_PKGS="ubuntu-minimal
    aptitude
    autoconf
    automake
    bzip2   
    cmake 
    curl 
    freebsd-buildutils
    g++ 
    gcc 
    libhtml-parser-perl 
    libbsd-dev
    libbz2-dev 
    libfreetype6-dev
    libmysqlclient15-dev 
    libgl1-mesa-dev 
    libglut3-dev
    libpcre3-dev 
    libssl-dev 
    libx11-dev 
    libxft-dev 
    libxi-dev 
    libxmu-dev 
    libxpm-dev 
    libxt-dev 
    libxml2-dev
    m4 
    make 
    libncurses5-dev 
    patch 
    python-dev 
    rsync 
    subversion 
    tcl8.4-dev 
    texinfo 
    wget
"

hardy_PKGS=""
intrepid_PKGS=cmake-gui
jaunty_PKGS=cmake-gui
karmic_PKGS=cmake-curses-gui
lucid_PKGS=cmake-curses-gui

MORE_PKGS=$(eval echo \$${UVERSION}_PKGS)

if [ ${UVERSION} = "lucid" ]; then  
   add-apt-repository "deb http://archive.canonical.com/ lucid partner"
fi

apt-get update

echo -n "Installing packages..."

echo > Ubuntu.log
if [ $? != 0 ] ; then
    echo "$0: Unable to create log file 'Ubuntu.log'.  Please run in writable directory."
    exit 1
fi
  
apt-get install -y $COMMON_PKGS >Ubuntu.log 2>&1
if [ $? -ne 0 ] ; then
    cat Ubuntu.log
    echo <<EOF 
Problem:  package $0 unknown.
Please report this problem (with full output above) to
dataclass@icecube.wisc.edu or icetray-dev@icecube.umd.edu"
Exiting in order to avoid problems later on
EOF
    fi
echo "okay."

echo "Installing packages"
apt-get install -y $COMMON_PKGS $MORE_PKGS

echo "Installing java"

apt-get install -y sun-java6-jdk
if [ $? -ne 0 ] ; then
    echo <<EOF 
Unable to find package 'sun-java6-jdk'
Ensure that the following lines are in your /etc/apt/sources.list:

  deb http://archive.ubuntu.com $UVERSION universe
  deb http://archive.ubuntu.com $UVERSION multiverse
 
It is safe to rerun this script until it works.
If you have further problems please report to 

   dataclass@icecube.wisc.edu or icetray-dev@icecube.wisc.edu

Exiting.
EOF
fi

echo "Done.  You can now build ports."



